<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>"> 
<meta charset="UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-1.8.0.js"></script> 
<script type="text/javascript">
	$(function(){
		$("#ch_checkall,#top_ch_checkall").click(function(){
			if(this.checked){
				$("input[name=ck_id]").attr("checked","checked");
			}else{
				$("input[name=ck_id]").removeAttr("checked");
			}		
		});
		$("table tr").mouseover(function(){
			$(this).css("background","#D3EAEF");
			$(this).siblings().css("background","white");
		});
		$("#deleteAll").on('click',function (){
			var beat=false;
			$("input[name=ck_id]").each(function(){
				if(this.checked){beat=true;}
			})
			if(beat){$('form[name=form1]').submit();}
			});
		});
		function inputnumber(e) {
	        e.value = (e.value.replace(/[^\d]/g, ''))
	    }
</script>

<link rel="stylesheet" type="text/css" href="css/maintable.css" ></link>
</head>
<body>
	<form action="AdminServlet.do"  name="form1" method="post" >
	<div class ="div_title">
			<div class="div_titlename"> <img src="images/san_jiao.gif" ><span>管理人员基本信息列表</span></div>
			<div class="div_titleoper">
				<input type="checkbox" id="top_ch_checkall"/> 全选 <a href="admin/admin_add.jsp"> <img src="images/add.gif"/>添加 </a> <a href="javascript:void(0)" id="deleteAll"><img src="images/del.gif"/>删除</a> </div>
	 </div>

	<input type="hidden" name="flag" value="deleteAll">
	<input type="hidden" name="pageIndex" value="${page.pageIndex}">
	 <table class="main_table" >
	       <tr>
	 				<th><input type="checkbox" id="ch_checkall" /></th>	<th>账号</th> 	<th>状态</th>	<th>备注</th>  <th>最后更新日期</th> 	<th>操作</th>
	 		</tr>
	 		<c:forEach var="a" items="${adminList }" varStatus="st">
	 		<tr>
	 				<td>
	 					<input type="checkbox" name="ck_id" value="${a.id}" /> 
	 				</td>
	 				<td>${a.adminName }</td>	
	 				<td>
	 					<c:choose>
				  			<c:when test="${a.state=='2'}">已锁定</c:when>
				  			<c:otherwise> </c:otherwise>
				  		</c:choose>				
	 				</td>	
	 				<td> <a title="${a.note}">
		 				<c:if test="${fn:length(a.note) > 10 }">
							${fn:substring(a.note,0,10)}...
						</c:if>
						<c:if test="${fn:length(a.note)  <= 10 }">
							${a.note}
						</c:if>
					</a></td>	
	 				
	 				<td><fmt:formatDate value="${a.editDate}" type="both" pattern="yyyy-MM-dd HH:mm"/></td>	
	 				<td>
	 				<c:choose>
				  			<c:when test="${a.state=='2'}"><a href="AdminServlet.do?flag=start&amp;pageIndex=${page.pageIndex}&amp;id=${a.id}">解锁</a> | </c:when>
				  			<c:otherwise><a href="AdminServlet.do?flag=stop&amp;pageIndex=${page.pageIndex}&amp;id=${a.id}">锁定</a> | 
				  						 <a href="AdminServlet.do?flag=searchForUpdate&id=${a.id}">修改</a> |  	</c:otherwise>
				  	</c:choose>  
		 					
		 			    <a href="AdminServlet.do?flag=delete&amp;pageIndex=${page.pageIndex}&amp;id=${a.id}">删除</a> 

	 				</td>
	 		</tr>
	 		</c:forEach>
	</table>
	</form>
	
	<div class="div_page" >
		<div class="div_page_left"> 共有 <label>${page.rowCount }</label> 条记录，当前第 <label>${page.pageIndex }</label> 页，共 <label>${page.pageCount }</label> 页	</div>		
		<div class="div_page_right" > 	
		<form action="AdminServlet.do"  id="loginForm" method="get" > 
			<c:choose>
				<c:when test="${page.hasPre }">
					<a href="AdminServlet.do?flag=manage&pageIndex=1">&nbsp;首页</a>
					<a href="AdminServlet.do?flag=manage&pageIndex=${page.pageIndex-1 }">&nbsp;上一页</a>  
				</c:when>
				<c:otherwise>
					&nbsp;首页
					&nbsp;上一页
				</c:otherwise>
			</c:choose>
			
			<c:choose>
				<c:when test="${page.hasNext }">
					<a href="AdminServlet.do?pageIndex=${page.pageIndex+1 }&amp;flag=manage">&nbsp;下一页</a>
					<a href="AdminServlet.do?flag=manage&pageIndex=${page.pageCount }">&nbsp;尾页</a>
				</c:when>
				<c:otherwise>
					&nbsp;下一页
					&nbsp;尾页
				</c:otherwise>
			</c:choose>
			
			<input type="hidden" name="flag" value="manage">
			<button onclick="$('#loginForm').submit();">转到&nbsp;&nbsp;</button>
			<input type="text" name="pageIndex" id="pageIndex" value="${page.pageIndex}" oninput="inputnumber(this)"/> &nbsp;页
			</form>
		</div>			
	</div>
	</body>
	</html>